using Admin.NET.Core;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MOKA.TPM.Application.Service;
using MOKA.TPM.Entity;
using MOKA.TPM.Service.Dto;
using MOKA.TPM.Utility;
using MOKA.TPM.Utility.Const;
using SqlSugar;

namespace MOKA.TPM.Service;

/// <summary>
/// TPM非采库存业务逻辑控制器
/// </summary>
[ApiDescriptionSettings(TPMConst.GroupName, Name = "TPM_PartStock", Order = 305)]
[NonUnify]
public class PartStockService : TPMBaseService, IDynamicApiController, ITransient
{
    private readonly Service_PartsStock _partsStockService;

    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="rep"></param>
    /// <param name="userManager"></param>
    /// <param name="accessor"></param>
    /// <param name="partsStockService"></param>
    /// <param name="dicService"></param>
    public PartStockService(UserManager userManager, IHttpContextAccessor accessor, ISqlSugarClient db, Service_PartsStock partsStockService, Service_SysDictDetail dicService)
                : base(userManager, dicService, accessor, db)
    {
        _partsStockService = partsStockService;
    }

    /// <summary>
    /// 查询数据
    /// </summary>
    /// <returns></returns>
    [ApiDescriptionSettings(Name = "DoQuery"), HttpPost]
    [AllowAnonymous]
    public async Task<CommonResult> DoQueryAsync(GetPartsStockInput obj)
    {
        LogHelper.Write("查询库存:", obj.ToString());
        CommonResult result = new CommonResult();

        try
        {
            var partsStockEntities = await _partsStockService.GetList(obj);

            if (partsStockEntities != null && partsStockEntities.Count > 0)
            {
                result.Data = partsStockEntities;
                result.Result = true;
            }
        }
        catch (Exception ex)
        {
            result.Data = null;
            result.Result = false;
            result.Error = ex.Message.ToString();
        }
        return result;
    }
}